package com.zonski.jbots.desktop.engine;

import com.zonski.jbots.game.entity.InputMind;
import com.zonski.jbots.game.entity.MinimalInputMind;

import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

/**
 * Created by IntelliJ IDEA.
 * User: Chris Glover
 * Date: 8/07/2004
 * Time: 11:44:11
 * To change this template use Options | File Templates.
 */
public class MinimalInputMindKeyListener extends KeyAdapter
{
    private MinimalInputMind mind;

    public int up = KeyEvent.VK_UP;
    public int down = KeyEvent.VK_DOWN;
    public int left = KeyEvent.VK_LEFT;
    public int right = KeyEvent.VK_RIGHT;
    public int bomb = KeyEvent.VK_Z;
    public int comet = KeyEvent.VK_X;
    public int egg = KeyEvent.VK_ENTER;

    public MinimalInputMindKeyListener(MinimalInputMind mind)
    {
        this.mind = mind;
    }

    public void keyPressed(KeyEvent event)
    {
        int keyCode = event.getKeyCode();
        setDown(keyCode, true);
    }

    public void keyReleased(KeyEvent event)
    {
        int keyCode = event.getKeyCode();
        setDown(keyCode, false);
    }

    private void setDown(int keyCode, boolean down)
    {
        if(keyCode == this.up)
        {
            mind.setDown(InputMind.SOUTH, down);
        }else if(keyCode == this.down){
            mind.setDown(InputMind.NORTH, down);
        }else if(keyCode == this.left){
            mind.setDown(InputMind.WEST, down);
        }else if(keyCode == this.right){
            mind.setDown(InputMind.EAST, down);
        }else if(keyCode == this.bomb){
            mind.setDown(InputMind.BOMB, down);
        }else if(keyCode == this.comet){
            mind.setDown(InputMind.COMET, down);
        }else if(keyCode == this.egg){
            mind.setDown(MinimalInputMind.EGG, down);
        }
    }
}
